<template>
  <div class="divBox relative">
    <el-card class="box-card" style="min-height: 80vh">
      <div slot="header" class="clearfix" style="margin-bottom: -20px ;">
        <div class="container">
          <el-form :inline="true" :model="queryForm" @submit.native.prevent>
            <el-form-item>
              <el-select v-model="queryForm.appid" placeholder="请选择app" class="width100" filterable clearable>
                <el-option
                  v-for="item in applist"
                  :key="item.appid"
                  :value="item.appid"
                  :label="item.appname">
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item v-if="this.selOptions.JavaInfo.level===0">
              <el-select v-model="queryForm.orgid" placeholder="请选择机构" class="width100" filterable clearable>
                <el-option
                  v-for="item in orglist"
                  :key="item.id"
                  :value="item.id"
                  :label="item.orgname">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-input v-model="queryForm.name" placeholder="请输入姓名" clearable
                        @keyup.enter.native="search()"></el-input>
            </el-form-item>
            <el-form-item>
              <el-input v-model="queryForm.account" placeholder="请输入账户" clearable
                        @keyup.enter.native="search()"></el-input>
            </el-form-item>


            <el-form-item>
              <el-select v-model="queryForm.status" placeholder="请选择审核状态" class="width100" filterable clearable>
                <el-option
                  v-for="item in selOptions.wlStatus"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label">
                </el-option>
              </el-select>
            </el-form-item>


            <el-form-item>
              <el-button @click="search()">查询</el-button>
              <el-button v-if="checkPermi(['goods:index:delete'])" type="danger" @click="batchUpdate()"
                         :disabled="dataListSelections.length <= 0">批量审核并打款
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle"
                style="width: 100%;" size="mini" :highlight-current-row="true"
                :header-cell-style=" {fontWeight:'bold'}">
        <el-table-column type="selection" header-align="center" align="center" width="50" :selectable="optionData"/>
        <el-table-column prop="id" label="主键1" >
        </el-table-column>
        <el-table-column prop="userid" label="用户信息" width="120px">
          <template slot-scope="scope">
            {{scope.row.userid}}  -  {{scope.row.name}}

          </template>
        </el-table-column>
        <el-table-column prop="account" label="账户" width="180px">
          <template slot-scope="scope">
            {{scope.row.account}}
            <el-tag type="success" size="mini" v-if="scope.row.type===0">支付宝</el-tag>
            <el-tag type="warn"  size="mini" v-else>银行卡</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="提现金额" >
          <template slot-scope="scope">
            {{(scope.row.amount-scope.row.rateamount)/100.0}}
          </template>
        </el-table-column>
        <el-table-column prop="rateamount" label="提现手续费" >
          <template slot-scope="scope">
            {{scope.row.rateamount/100.0}}
          </template>
        </el-table-column>
        <el-table-column prop="ordersn" label="订单编号" width="280">
          <template slot-scope="scope">
            {{scope.row.ordersn}}<br/>
            {{scope.row.order3ordersn}}
          </template>

        </el-table-column>
        <el-table-column prop="partnerstatus" label="身份" >
          <template slot-scope="scope">
            <el-tag type="info" size="mini" v-if="scope.row.partnerstatus===0">普通用户</el-tag>
            <el-tag type="success" size="mini" v-if="scope.row.partnerstatus===1||scope.row.partnerstatus===2||scope.row.partnerstatus===3">激活用户</el-tag>
            <el-tag type="warning" size="mini" v-if="scope.row.partnerstatus===9">合作伙伴</el-tag>
          </template>

        </el-table-column>
        <el-table-column prop="status" label="状态" >
          <template slot-scope="scope">
            <el-tag type="info" size="mini" v-if="scope.row.status===0">待审核</el-tag>
            <el-tag type="warning" size="mini" v-if="scope.row.status===1">审核通过</el-tag>
            <el-tag type="success" size="mini" v-if="scope.row.status===2">已打款</el-tag>
            <el-tag type="danger"  size="mini"v-if="scope.row.status===3">拒绝</el-tag>
            <el-tag type="danger" size="mini" v-if="scope.row.status===98" >回退</el-tag>
            <el-tag type="danger" size="mini" v-if="scope.row.status===99" >打款失败</el-tag>
          </template>

        </el-table-column>
        <el-table-column prop="info" label="拒绝原因"  width="150"/>
        <el-table-column prop="remark" label="备注"  width="150"/>

        <el-table-column prop="appname" label="app" width="120" :show-overflow-tooltip="true"/>
        <el-table-column prop="orgname" label="机构" width="120" :show-overflow-tooltip="true"/>
        <el-table-column prop="createtime" label="申请时间"  width="150"/>
        <el-table-column prop="payfinishtime" label="打款时间"  width="150"/>
<!--        <el-table-column prop="updatetime" label="更新时间" >-->
<!--        </el-table-column>-->
        <el-table-column v-if="checkPermi(['withdrawlog:index:update'])&&checkPermi(['withdrawlog:index:update'])" fixed="right" header-align="center" align="center" width="150" label="操作">
          <template slot-scope="scope">
            <el-button type="text" v-if="checkPermi(['withdrawlog:index:update'])" size="small" @click="addOrUpdateHandle(scope.row.id)">审核</el-button>
            <el-button type="text" v-if="checkPermi(['withdrawlog:index:update'])&&scope.row.status===99" size="small"  @click="change(scope.row)">回退
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="tableForm.pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="tableForm.pageSize"
        :total="tableForm.total"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-card>
    <!-- 表单弹窗, 新增数据和修改数据 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from './withdrawlog-add-and-update'
import api from '@/api/api'
import { checkPermi } from '@/utils/permission'
import utils from '@/api/utils'

export default {
  components: {
    AddOrUpdate
  },
  data() {
    return {
      selOptions: {},
      dataList: [],
      applist:[],
      orglist:[],
      queryForm: {
        id: '',
        userid: '',
        appdi: '',
        orgid: '',
        name: '',
        account: '',
        info: '',
        type: '',
        amount: '',
        status: '',
        timeVal: []
      },
      tableForm: {
        pageIndex: 1,
        pageSize: 10,
        total: 0
      },
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  mounted() {
    this.selOptions = this.$constants.selOptions
    this.search()
    utils.getAppList().then(res => {this.applist=res.datalist});
    utils.getOrgList().then(res => {this.orglist=res.datalist});
  },
  methods: {
    checkPermi,
    // 每页数
    sizeChangeHandle(val) {
      this.tableForm.pageSize = val
      this.tableForm.pageIndex = 1
      this.search()
    },
     optionData(row) {
  return row.status===0;
},
    // 当前页
    currentChangeHandle(val) {
      this.tableForm.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },
    change(row) {
      let postData = { id: row.id }
      postData.status = 98
      api.post('rest/vabc/withdrawlog/update', postData).then(res => {
        this.$message.success('操作成功')
        // row.status = postData.status
        this.getDataList()
      })
    },
    // 删除
    batchUpdate(id) {
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      this.$confirm(`您确定对[id=${ids.join(',')}]进行[打款]操作吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let postData = { ids: ids.join(',') }
        api.post('rest/vabc/withdrawlog/batchUpdate', postData).then(res => {
          this.$message.success('操作成功')
          this.getDataList()
        })
      })
    },
    search() {
      this.tableForm.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      this.dataListLoading = true
      let postData = {
        'order': 'desc',
        'column': 'id'
      }
      Object.assign(postData, this.queryForm, this.tableForm)
      //postData.name=api.getLikeValue( postData.name);
      postData.userid = api.getLikeValue(postData.userid)
      postData.name = api.getLikeValue(postData.name)
      postData.account = api.getLikeValue(postData.account)
      postData.info = api.getLikeValue(postData.info)
      postData.type = api.getLikeValue(postData.type)
      postData.amount = api.getLikeValue(postData.amount)

      api.post('rest/vabc/withdrawlog/list', postData).then(res => {
        this.dataList = res.datalist
        this.tableForm.total = res.total
      }).finally(() => {
        this.dataListLoading = false
      })
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    onchangeTime(e) {
      this.queryForm.createtime_begin = e[0]
      this.queryForm.createtime_end = e[1]
    }
  }
}
</script>
